trigger AccountRelation on Purchase_Object__c (before update,before insert) {
   
   //For every Purchase_Object__c record, add its associated Id and Oracle_Acc_Number__c entry to a set so there are no duplicates.//

     Set<Id> poId = new Set<id>();
     Set<Decimal> orno= new Set<Decimal>();
   for (Purchase_Object__c po : Trigger.new){
       poId.add(po.id);
       orno.add(po.Oracle_Acc_Number__c);
       }
  List<Account> Accounts = [Select OwnerId,id,Oracle_Account_Number__c from account where Oracle_Account_Number__c in : orno];
    System.debug('Accccc' + Accounts);

// Query the Oracle_Account_Number__c and Ownerid for their associated  Oracle_Account_Number__c and place the results in a map. 
 Map<id,Account> mapoNid = new Map<id,Account>([Select id,Ownerid,Oracle_Account_Number__c from Account where  id In : Accounts]);
    System.debug('map' + mapoNid);
  
// Now use the map to set the appropriate OwnerId on every Purchase_Object__c processed  by the trigger.//
 for(Account a : Accounts){                 
     for(Purchase_Object__c po :Trigger.New){
          if(po.Oracle_Acc_Number__c == a.Oracle_Account_Number__c){
             po.Account__c =  mapoNid.get(a.Id).Id; 
            System.debug('acccid'   +   po.OwnerId);             
       }
      }     
     }
   }